<?php

declare(strict_types=1);

namespace App\Command;

use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Psr\Container\ContainerInterface;

/**
 * @Command
 */
#[Command]
class Req extends HyperfCommand
{
    /**
     * @var ContainerInterface
     */
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;

        parent::__construct('req');
    }

    public function configure()
    {
        parent::configure();
        $this->setDescription('请求测试');
    }

    public function handle()
    {
        $org = 12;
        $pv = 0;
        $url = "https://api.traveltimeslvwen.com/frontend/creation?org={$org}&limit=10000";
        $client = new \GuzzleHttp\Client();
        $res = json_decode($client->request('GET', $url)->getBody()->getContents(), true)['rows'];
        foreach ($res as $item) {
            $pv += $item['pv'];
        }
        $this->line("org={$org}的pv总和为：$pv");
    }
}
